package lean;
import java.util.Scanner;
public class xiangmu {
    public static void main(String[] agrs){
        String[]names=new String[4];
        String[]dishMegs=new String[4];
        int[]times=new int[4];
        String[]addresses=new String[4];
        int[] states=new int[4];
        double[]sumprices=new double[4];
        String[]disNames={"红烧带鱼","鱼香肉丝","时令蔬菜"};
        double[]prices=new double[]{38.0,20.0,10.0};
        int[] praiseNUms=new int[3];
        //names[0]="张晴";
        //dishMegs[0]="红烧带鱼2份";
        //times[0]=12;
        //addresses[0]="天成路207号";
        //sumprices[0]=76.0;
        //states[0]=1;
        //names[1]="张晴";
        //dishMegs[1]="鱼香肉丝2份";
        //times[1]=18;
        //addresses[1]="天成路207号";
        //sumprices[1]=45.0;
        //states[1]=0;
         Scanner sc=new Scanner(System.in);
         int num=-1;
         boolean isExit=false;
         System.out.println("\n欢迎使用k38订餐系统");
         do {
             System.out.println("************************");
             System.out.println("1,我要订餐");
             System.out.println("2,查看餐袋");
             System.out.println("3,签收订单");
             System.out.println("4,删除订单");
             System.out.println("5,我要点赞");
             System.out.println("6,退出系统");
             System.out.println("************************");
             System.out.println("请选择:");
             int choose = sc.nextInt();
             switch (choose) {
                 case 1:
                     System.out.println("***我要订餐");
                     Boolean isAdd=false;
                     for(int j=0;j<names.length;j++){
                         if(names[j]==null){
                             isAdd=true;
                             System.out.println("请输入订餐的姓名:");
                             String name=sc.next();
                             System.out.println("序号"+"\t"+"菜名"+"\t"+"单价"+"\t"+"点赞数");
                             for(int i=0;i< disNames.length;i++){
                                 String price=sumprices[i]+"元";
                                 String priaiseNum=(praiseNUms[i]>0?praiseNUms[i]+"赞":"0");
                                 System.out.println((i+1)+"\t"+ disNames[i]+"\t"+price+" \t"+priaiseNum);
                             }
                             System.out.print("请选择你要点的菜品编号:");
                             int chooseDish=sc.nextInt();
                             System.out.print("请选择你需要的分数");
                             int number=sc.nextInt();
                             String disMeg= disNames[chooseDish-1]+""+number+"份";
                             double sumprice=prices[chooseDish-1]*number;
                             double deliCharge=(sumprice>=60)?0:10;
                             System.out.println("请输入送餐时间(送餐时间是8至23点间整点送餐):");
                             int time=sc.nextInt();
                             while(time<8||time>23){
                                 System.out.println("你的输入有误，请重新输入!");
                                 time=sc.nextInt();
                             }
                             System.out.print("请输入送餐地址:");
                             String address=sc.next();
                             System.out.println("订餐成功!");
                             System.out.println("你订的是:"+disMeg);
                             System.out.println("送餐时间:"+time+"点");
                             System.out.println("餐费:"+sumprice+"元，送餐费"+deliCharge+"元，总计:"+(sumprice+deliCharge)+"元.");
                             names[j]=name;
                             dishMegs[j]=disMeg;
                             times[j]=time;
                             addresses[j]=address;
                             sumprices[j]=sumprice+deliCharge;
                             break;
                         }
                         if(isAdd){
                             System.out.println("对不起，你的餐袋已满!");

                     }
                     break;}
                 case 2:
                     System.out.println("***查看餐袋***");
                     System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t\t总金额\t订单状态");
                     for(int i=0;i<names.length;i++){
                         if(names[i]!=null) {
                             String state = (states[i] == 0 ? "已预定" : "已完成");
                             String date = times[i] + "点";
                             String sumprice = sumprices[i] + "元";
                             System.out.println((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + date + "\t" + addresses[i] + "\t" + sumprice + "\t" + state);
                         }
                         }
                     break;
                 case 3:
                     System.out.println("****签收订单***");
                     boolean isSignFind=false;
                     System.out.print("请选择要签收的订单序号:");
                     int signOrderId=sc.nextInt();
                     for(int i=0;i<names.length;i++){
                         if(names[i]!=null&&states[i]==0&&signOrderId==i+1){
                             states[i]=1;
                             System.out.println("订单签收成功!");
                             isSignFind=true;
                         }else if(names[i]!=null&&states[i]==1&&signOrderId==i+1){
                             System.out.println("你选择的订单已完成签收，不能再次签收!");
                             isSignFind=true;

                         }
                     }
                     if(!isSignFind) {
                         System.out.println("你选择的订单不存在!");
                     }
                     break;
                 case 4:
                     System.out.println("***删除订单***");
                     boolean isDelFind=false;
                     System.out.print("请输入要删除的订单序号:");
                     int intdelId=sc.nextInt();
                     for(int i=0;i<names.length;i++){
                         if(names[i]!=null&&states[i]==1&&intdelId==i+1){
                             isDelFind=true;
                             for(int j=intdelId-1;j<names.length-1;j++){
                                 names[j]=names[j+1];
                                 dishMegs[j]=dishMegs[j+1];
                                 times[j]=times[j+1];
                                 addresses[j]=addresses[j+1];
                                 states[j]=states[j+1];
                                 sumprices[j]=sumprices[j+1];
                             }
                             int endIndex=names.length-1;
                             names[endIndex]=null;
                             dishMegs[endIndex]=null;
                             times[endIndex]=0;
                             addresses[endIndex]=null;
                             states[endIndex]=0;
                             sumprices[endIndex]=0;
                             System.out.println("删除成功!");
                             break;
                         }
                         else if (names[i]!=null&&states[i]==0&&intdelId==i+1);{
                             System.out.println("你选择的订单未签收,不能删除!");
                             isDelFind=true;
                             break;
                         }
                     }
                     if(!isDelFind){
                         System.out.println("你要删除的订单不存在!");
                     }
                     break;
                 case 5:
                     System.out.println("***我要点赞***");
                     System.out.println("序号"+"\t"+"菜名"+"\t"+"单价");
                     for(int i=0;i<disNames.length;i++){
                         String price=prices[i]+"元";
                         String priaiseNum=(praiseNUms[i]>0?praiseNUms[i]+"赞":"");
                         System.out.println((i+1)+"\t"+ disNames[i]+"\t"+price+"\t"+priaiseNum);
                     }
                     System.out.print("请选择你要点赞的菜品序号:");
                     int praiseNum=sc.nextInt();
                     praiseNUms[praiseNum-1]++;
                     System.out.println("点赞成功!");
                     break;
                 case 6:
                     isExit = true;
                     break;
                 default:
                     isExit = true;
                     break;
             }
             if (!isExit) {
                 System.out.println("输入0返回");
                 num = sc.nextInt();
             } else {
                 break;
             }
         }while(num==0);



         }
    }

